﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace HaiFang
{
    [Serializable]
    public class ProxyGeneralType
    {
        private static string PROCEDURE_QueryGeneralType = "QueryGeneralType";
        private static string PROCEDURE_InsertGeneralType = "InsertGeneralType";

        //@CurrUserID			int = null,					--管理员编号
        //@GeneralType		varchar(128)				
        public static IList<GeneralTypeInfo> QueryGeneralType(int CurrUserID, string GeneralType)
        {
            IList<GeneralTypeInfo> list = new List<GeneralTypeInfo>();
            try
            {
                using (SqlHelper helper = new SqlHelper())
                {
                    #region 构造参数
                    string comandText = PROCEDURE_QueryGeneralType;
                    List<SqlParameter> Parameters = new List<SqlParameter>();
                    Parameters.Add((new SqlParameter("@CurrUserID", CurrUserID)));
                    Parameters.Add(new SqlParameter("@GeneralType", GeneralType));
                    #endregion

                    #region 获取执行结果
                    DataTable dt = helper.ExecuteDataTable(comandText, CommandType.StoredProcedure, Parameters);
                    list = helper.GetObjects<GeneralTypeInfo>(dt);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LogHelper.Writelog(LogType.LogType_Error, ex.Message, ex);
            }
            return list;
        }

        //@CurrUserID			int = null,					--管理员编号
        //@UseFlag			tinyint,					--1:insert 2:update   3:delete
        //@AutoID				bigint=0,					--@UseFlag为1时传0，其它操作传编号值
        //@GeneralType		varchar(128),				--'所属专业','文件类型'
        //@GeneralValue1		varchar(128),				--名称
        //@ErrorMSG			int	output					--100：名称存在  0：正确；其他：错误	
        public static void InsertGeneralType(int CurrUserID, int UseFlag, int AutoID, string GeneralType, string GeneralValue1, out int ErrorMSG)
        {
            ErrorMSG = -1;
            try
            {
                using (SqlHelper helper = new SqlHelper())
                {
                    #region 构造参数
                    string comandText = PROCEDURE_InsertGeneralType;
                    List<SqlParameter> Parameters = new List<SqlParameter>();
                    Parameters.Add((new SqlParameter("@CurrUserID", CurrUserID)));
                    Parameters.Add(new SqlParameter("@UseFlag", UseFlag));
                    Parameters.Add(new SqlParameter("@AutoID", AutoID));
                    Parameters.Add(new SqlParameter("@GeneralType", GeneralType));
                    Parameters.Add(new SqlParameter("@GeneralValue1", GeneralValue1));
                    Parameters.Add(new SqlParameter()
                    {
                        ParameterName = "@ErrorMSG",
                        SqlDbType = SqlDbType.Int,
                        Direction = ParameterDirection.Output,
                        Value = ErrorMSG
                    });
                    #endregion

                    #region 获取执行结果
                    helper.Execute(comandText, CommandType.StoredProcedure, Parameters);
                    #endregion

                    #region 获取output值
                    foreach (SqlParameter sp in Parameters)
                    {
                        if (sp.ParameterName == "@ErrorMSG")
                        {
                            ErrorMSG = helper.GetInt(sp.Value);
                            break;
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                LogHelper.Writelog(LogType.LogType_Error, ex.Message, ex);
            }
        }
    }

    [Serializable]
    public class GeneralTypeInfo
    {
        public int AutoID { get; set; }
        public string GeneralType { get; set; }
        public int GeneralSort { get; set; }
        public string GeneralValue1 { get; set; }
        public string GeneralValue2 { get; set; }
        public string GeneralValue3 { get; set; }
        public string GeneralValue4 { get; set; }
        public string GeneralValue5 { get; set; }
        public string GeneralValue6 { get; set; }
        public DateTime CreateTime { get; set; }
        public string Description { get; set; }
    }
}